package com.comunity_cloud.client.view2;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Point;

import javax.swing.JDialog;
import javax.swing.JProgressBar;

import com.comunity_cloud.client.controller.MainController2;

public class ProgressDialog extends JDialog{

	private JProgressBar progressBar;

	private static ProgressDialog instance = new ProgressDialog(MainController2.getInstance().getMainView());
	
	private ProgressDialog(Frame owner) {
		super(owner,true);
		setUndecorated(true);
		progressBar = new JProgressBar();
		setLayout(new BorderLayout());
		add(progressBar);
		setSize(350,30);
		Point point = getLocation();
		setLocation(point.x+owner.getWidth()/2 - 175, point.y + owner.getHeight()/2 - 15);
		
	}
	
	public void showDialog() {
		new Thread(){
			public void run() {
				setVisible(true);
			}
		}.start();
	}
	
	public void setProgressText(String text){
		progressBar.setStringPainted(true);
		progressBar.setString(text);		
	}
	
	public void setValue(int value) {
		progressBar.setValue(value);
	}
	
	public static ProgressDialog getInstance() {
		return instance;
	}

	public void increaseProgress(int value) {
		progressBar.setValue(progressBar.getValue() + value);
		// TODO Auto-generated method stub
		
	}

	public void hideDialog() {
		progressBar.setValue(0);
		dispose();
	}

	public void setProgress(int progress) {
		progressBar.setValue(progress);
	}
}
